import axios from '@/api'
import { IPower } from './power'

export interface IBasic {
  task_id?: string;
  s_a_id: string;
}

export interface IUserLogin {
  request: {
    usr_sfz: string;
    usr_psw: string;
  },
  response: {
    token: string;
    token2: string;
    usr_id: string;
    usr_nickname: string;
    usr_tel: string;
    usr_sfz: string;
  }
}

export interface IAdmin {
  usr_id: string;
  s_a_id: string;
  work_place: string;
  pow_gp_id: string;
  task_ids: string;
  statu: string;
  readme: string;
}

export interface IGetAdminList {
  request: Partial<IAdmin>,
  response: Array<IAdmin>
}

class CommonServices {
  constructor() { }

  /**
   * 用户登录
   *
   * @returns
   * @memberof UserServices
   */
  login(data: IUserLogin['request']) {
    return axios.post<unknown, Api.ResponseOptions<IUserLogin['response']>>('/btpub/user/pswd-login', data)
  }

  /**
   * 获取管理员列表
   *
   * @param {IGetAdminList['request']} data
   * @returns
   * @memberof UserServices
   */
  getAdminList(data: IGetAdminList['request']) {
    return axios.post<unknown, Api.ResponseOptions<IGetAdminList['response']>>('/btsys/admin/get-admin-list', data)
  }

  /**
   * 编辑/添加管理员
   *
   * @param {IAdmin} data
   * @returns
   * @memberof UserServices
   */
  updateAdmin(data: IAdmin) {
    return axios.post<unknown, Api.ResponseOptions<IGetAdminList['response']>>('/btsys/admin/edit-admin', data)
  }

  /**
   * 删除管理员
   *
   * @param {string} id
   * @returns
   * @memberof UserServices
   */
  deleteAdmin(id: string) {
    return axios.post<unknown, Api.ResponseOptions>('/btsys/admin/del-admin', { usr_id: id })
  }

  /**
   * 获取银行卡类型
   *
   * @returns
   * @memberof CommonServices
   */
  getBankType() {
    return axios.post<unknown, Api.ResponseOptions>('/btpub/pub/get-bank-list')
  }

  /**
   * 获取菜单
   *
   * @returns
   * @memberof CommonServices
   */
  getMenu() {
    return axios.post<unknown, Api.ResponseOptions<IPower[]>>('/btsys/pub/get-menu')
  }
}

export const commonServices = new CommonServices()

export default CommonServices